package com.zztl.infiniteBand.util.language

import android.content.Context
import android.content.res.Configuration

import com.zztl.infiniteBand.R

import java.util.Locale

/**
 * @author swl
 * date 2019/8/12 17:41
 */
object LanguageManager {
    private val TAG = "LocalManageUtil"

    /**
     * 获取系统的locale
     *
     * @return Locale对象
     */
    fun getSystemLocale(context: Context): Locale {
        return SPUtil.getInstance(context)!!.systemCurrentLocal
    }

    fun getSelectLanguage(context: Context): String {
        when (SPUtil.getInstance(context)!!.selectLanguage) {
            0 -> return context.getString(R.string.英语)
            else -> return context.getString(R.string.简体中文)
        }
    }

    /**
     * 获取选择的语言设置
     *
     * @param context
     * @return
     */
    fun getSetLanguageLocale(context: Context): Locale {

        when (SPUtil.getInstance(context)!!.selectLanguage) {
            0 -> return  Locale.ENGLISH
            else -> return Locale.CHINA
        }
    }


    fun saveSystemCurrentLanguage(context: Context) {
        SPUtil.getInstance(context)!!.systemCurrentLocal = LanguageUtil.getSystemLocal(context)
    }

    /**
     * 保存系统语言
     * @param context
     * @param newConfig
     */
    fun saveSystemCurrentLanguage(context: Context, newConfig: Configuration) {

        SPUtil.getInstance(context)!!.systemCurrentLocal = LanguageUtil.getSystemLocal(newConfig)
    }

    fun saveSelectLanguage(context: Context, select: Int) {
        SPUtil.getInstance(context)!!.saveLanguage(select)
        LanguageUtil.setApplicationLanguage(context)
    }
}
